<!-- UserModel.php-->
<?php 
	require '../common/ConnDB.php';
	require '../common/config.php';
	require 'Model.php';
	class SoModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getSoList(){
			$sql = 'select * from society';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}

		function getsocietyinfor($activity){
			$sql = "select * from society where activity like '%".$activity."%' limit 0,10 ";;
			$data = $this->conn->query($sql);
			return $data;
		}

		function getUserByID($id){
			$sql = "select * from society where acid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatesociety($data){
			if(!empty($_FILES["acphoto"]["name"])){
  				$acphoto = parent::uploadfile('acphoto','../images/',array('png','jpg','gif'));
  				//var_dump($acphoto);
  			}
		    else{
		  		$acphoto='';
		  	}
		  	$so = array(
				'acid' =>$_POST['acid'],
				'activity' => $_POST['activity'],
				'dename' => $_POST['dename'],
				'signifi' => $_POST['signifi'],
				'time' => $_POST['time'],
				'place' => $_POST['place'],
				'acphoto' => $acphoto
				);
			$sql="update society set acid='$so[acid]',activity='$so[activity]',dename='$so[dename]',signifi='$so[signifi]',time='$so[time]',place='$so[place]',acphoto='$so[acphoto]' where acid=".$so['acid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addSo($data){
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["acphoto"]["name"])){
  				$acphoto = parent::uploadfile('acphoto','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$acphoto='';
		  	}
			$user = array(
				'acid' =>'',
				'activity' => $data['activity'],
				'dename' => $data['dename'],
				'signifi' => $data['signifi'],
				'time' => $data['time'],
				'place' => $data['place'],
				'acphoto' => $acphoto
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
			/*$sql = "insert into users values ('$user[uid]','$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";*/
			$sql="insert into society ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Delsociety($id){
			$sql = "Delete from society where acid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>